package jdk.thread.lock;

import lombok.SneakyThrows;


/**
 * Thread实例的join方法，调用join方法的线程会等被调用join方法的线程执行完毕后才开始继续执行
 */
public class JoinTest {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000l);
                System.out.println("货物清点完成！");
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000l);
                System.out.println("货物装车完成！");
            }
        });

        t1.start();
        t1.join();
        t2.start();
        t2.join();
        System.out.println("货车出发！！");
    }
}
